<template>
  <van-icon 
  :color="value === 1 ? '#e5645f' : ''"
  :name="value ===1 ? 'good-job':'good-job-o'"
  @click="onlikes"
   />
</template>
<script>
import {addlikings,dellikings} from '@/api/article.js'
export default {
  props: {
    value: {
      type: Number,
      required: true,
    },
    articleId: {
      type: [Number, String,Object],
      required: true,
    },
  },
  methods:{
async onlikes(){
  let status = -1
   try {
    if(this.value === 1){
      //已点赞--取消点赞
      await dellikings(this.articleId)
    }else{
      //未点赞--点击点赞
      await addlikings(this.articleId)
      status =1
    }
    this.$emit('input',status)
    this.$toast.success(status === 1 ? '点赞成功':'取消点赞')
   } catch (error) {
    this.$toast.fail('操作失败，请重试')
   }
  }
 }
};
</script>

<style>
</style>